import java.awt.Graphics;
import java.util.ArrayList;

public class Stop {
	private int stopID;
	private String customName;
	private ArrayList<Integer> routes = new ArrayList<Integer>();
	private String direction;
	private int xPos;
	private int yPos;
	private int SbesTotalHeight;
	private ArrayList<StopBoxEntry> sbes = new ArrayList<StopBoxEntry>();
	private Graphics g;
	
	public Stop(int tempID, String tempName, ArrayList<Integer> tempRoutes, String tempDir, int tempX, int tempY, Graphics g) {
		this.stopID = tempID;
		this.customName = tempName;
		this.routes = tempRoutes;
		this.direction = tempDir;
		this.xPos = tempX;
		this.yPos = tempY;
		this.g = g;
	}

	public void setStopID(int stopID) {
		this.stopID = stopID;
	}
	
	public int getStopID() {
		return stopID;
	}
	
	public void setCustomName(String customName) {
		this.customName = customName;
	}
	
	public String getCustomName() {
		return customName;
	}

	public void setDirection(String direction) {
		this.direction = direction;
	}

	public String getDirection() {
		return direction;
	}

	public void addRoute(int route) {
		this.routes.add(route);
	}

	public ArrayList<Integer> getRoutes() {
		return routes;
	}

	public void setYPos(int yPos) {
		this.yPos = yPos;
	}

	public int getYPos() {
		return yPos;
	}

	public void setXPos(int xPos) {
		this.xPos = xPos;
	}

	public int getXPos() {
		return xPos;
	}

	public void setSbes(ArrayList<StopBoxEntry> sbes) {
		this.sbes = sbes;
		this.assessSbesTotalHeight();
	}
	
	public ArrayList<StopBoxEntry> getSbes() {
		return sbes;
	}
	
	public void sbesAdd(StopBoxEntry sbe) {
		sbes.add(sbe);
		this.assessSbesTotalHeight();
	}
	
	public void clearSbes() {
		sbes = new ArrayList<StopBoxEntry>();
	}

	private void assessSbesTotalHeight() {
		this.SbesTotalHeight = 0;
		for (StopBoxEntry sbe : sbes) {
			this.SbesTotalHeight += sbe.getHeight();
		}
	}

	public int getSbesTotalHeight() {
		return SbesTotalHeight;
	}

	public void drawStopBoxes() {
		int sbeXPos = this.xPos;
		int sbeYPos = this.yPos;
		for (StopBoxEntry sbe : sbes) {
			sbe.draw(sbeXPos, sbeYPos, g);
			sbeYPos += sbe.getHeight();
		}
	}

	public void sbesAddArrivals() {
		DataLoader dl = new DataLoader();
		ArrayList<Arrival> arrs = dl.loadArrivals(this.stopID);
		for (Arrival a : arrs) {
			sbesAdd(new StopBoxArrivalEntry(a));
		}
	}
}
